package linkedList;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 玩牌：
 * 1. 造牌：①类   ②生成牌
 * 2. 洗牌
 * 3. 3个人，每人5张玩去~
 */


class Card{
    public int rank;
    public String suit;

    @Override
    public String toString() {
        return "[ 牌号" + rank +
                ", 花色" + suit+" ]";
    }
}


public class playingCards {

    //买一副牌！
    public List<Card> buyCard(){
        List<Card> list = new ArrayList<>();
        String[] suit = {"♥","♠","♦","♣"};

        for(int i = 0;i<4;i++){
            for (int j = 1; j <= 13; j++) {
                Card card = new Card();
                card.suit = suit[i];
                card.rank = j;
                list.add(card);
            }
        }
        return list;
    }


    //交换牌!(从最后一个开始，与之前的任意一张牌进行交换！)
    public void SwapCard(int cur_index, int Swap_index, List<Card> list){
        Card tmpCard = list.get(cur_index);
        list.set(cur_index, list.get(Swap_index));
        list.set(Swap_index, tmpCard);
    }
    public void shuffle(List<Card> list){
        for (int i = list.size()-1; i >0 ; i--) {
            Random random = new Random();
            int Swap_index = random.nextInt(i);
            SwapCard(i, Swap_index,list);
        }

    }

    //玩！3人每人5张牌
    public void playing(List<Card> list){
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        List< List<Card> > hand = new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);

        for (int i = 0; i < 5 ; i++) {
            for (int j = 0; j < 3; j++) {
                hand.get(j).add(list.get(0));
                list.remove(0);
            }
        }
        for (int i = 0; i < hand.size(); i++) {
            System.out.println(hand.get(i));
        }



    }










    public static void main(String[] args) {
        playingCards playingCards = new playingCards();

        System.out.println("  ====买牌====  ");
        List<Card> list = playingCards.buyCard();
        System.out.println(list);

        System.out.println("  ====洗牌====");
        playingCards.shuffle(list);
        System.out.println(list);

        System.out.println("  ====玩牌====");
        playingCards.playing(list);

        System.out.println("  ====剩下的牌====");
        System.out.println(list);
    }

}
